﻿@inherits BaseComponent
@typeparam TItem
@using Blazorise.Scheduler.Extensions
@using Blazorise.Scheduler.Utilities
<Modal @ref="@modalRef">
    <ModalContent Centered>
        <ModalHeader>
            <ModalTitle>
                @ModalTitle
            </ModalTitle>
            <CloseButton />
        </ModalHeader>
        <ModalBody>
            <Validations @ref="@validationsRef" Mode="ValidationMode.Manual">
                @if ( TitleAvailable )
                {
                    <Validation Validator="@OnValidateTitle">
                        <Field>
                            <FieldLabel>@Localizer.Localize( Scheduler.Localizers?.TitleLocalizer, LocalizationConstants.Title )</FieldLabel>
                            <FieldBody>
                                <TextEdit @bind-Text="@Title" Autofocus>
                                    <Feedback>
                                        <ValidationError />
                                    </Feedback>
                                </TextEdit>
                            </FieldBody>
                        </Field>
                    </Validation>
                }
                @if ( StartAvailable )
                {
                    <Fields>
                        <Validation Validator="@OnValidateStartDate">
                            <Field ColumnSize="ColumnSizeIs12OnMobileIs6OnTablet">
                                <FieldLabel>@Localizer.Localize( Scheduler.Localizers?.StartLocalizer, LocalizationConstants.Start )</FieldLabel>
                                <FieldBody>
                                    <DatePicker TValue="DateOnly" Date="@StartDate" DateChanged="@OnStartDateChanged" StaticPicker="false" InputMode="DateInputMode.Date" FirstDayOfWeek="@FirstDayOfWeek">
                                        <Feedback>
                                            <ValidationError />
                                        </Feedback>
                                    </DatePicker>
                                </FieldBody>
                            </Field>
                        </Validation>
                        @if ( !AllDayAvailable || !AllDay )
                        {
                            <Validation Validator="@OnValidateStartTime">
                                <Field ColumnSize="ColumnSizeIs12OnMobileIs6OnTablet">
                                    <FieldLabel>&nbsp;</FieldLabel>
                                    <FieldBody>
                                        <TimePicker TValue="TimeOnly" Time="@StartTime" TimeChanged="@OnStartTimeChanged" StaticPicker="false" TimeAs24hr />
                                    </FieldBody>
                                </Field>
                            </Validation>
                        }
                    </Fields>
                }
                @if ( EndAvailable )
                {
                    <Fields>
                        <Validation Validator="@OnValidateEndDate">
                            <Field ColumnSize="ColumnSizeIs12OnMobileIs6OnTablet">
                                <FieldLabel>@Localizer.Localize( Scheduler.Localizers?.EndLocalizer, LocalizationConstants.End )</FieldLabel>
                                <FieldBody>
                                    <DatePicker @bind-Date="@EndDate" StaticPicker="false" InputMode="DateInputMode.Date" FirstDayOfWeek="@FirstDayOfWeek">
                                        <Feedback>
                                            <ValidationError />
                                        </Feedback>
                                    </DatePicker>
                                </FieldBody>
                            </Field>
                        </Validation>
                        @if ( !AllDayAvailable || !AllDay )
                        {
                            <Validation Validator="@OnValidateEndTime">
                                <Field ColumnSize="ColumnSizeIs12OnMobileIs6OnTablet">
                                    <FieldLabel>&nbsp;</FieldLabel>
                                    <FieldBody>
                                        <TimePicker @bind-Time="@EndTime" StaticPicker="false" TimeAs24hr />
                                    </FieldBody>
                                </Field>
                            </Validation>
                        }
                    </Fields>
                }
                @if ( AllDayAvailable )
                {
                    <Field>
                        <FieldBody>
                            <Check TValue="bool" @bind-Checked="@AllDay">
                                @Localizer.Localize( Scheduler.Localizers?.AllDayLocalizer, LocalizationConstants.AllDay )
                            </Check>
                        </FieldBody>
                    </Field>
                }

                @if ( DescriptionAvailable )
                {
                    <Field>
                        <FieldLabel>@Localizer.Localize( Scheduler.Localizers?.DescriptionLocalizer, LocalizationConstants.Description )</FieldLabel>
                        <FieldBody>
                            <MemoEdit @bind-Text="@Description" Rows="4" />
                        </FieldBody>
                    </Field>
                }
            </Validations>
            @if ( customValidationErrors.Any() )
            {
                <Paragraph TextColor="TextColor.Danger" Margin="MarginIs0FromBottom">
                    <UnorderedList Margin="MarginIs0FromBottom">
                        @foreach ( var error in customValidationErrors )
                        {
                            <UnorderedListItem>@error</UnorderedListItem>
                        }
                    </UnorderedList>
                </Paragraph>
            }
        </ModalBody>
        <ModalFooter Flex="FlexJustifyContentBetweenAlignItemsCenter">
            <Div>
                <Button Color="Color.Danger" Outline Clicked="@Delete">
                    <Icon Name="IconName.Delete" Margin="MarginIs2FromEnd" />
                    @Localizer.Localize( Scheduler.Localizers?.DeleteOccurrenceLocalizer, LocalizationConstants.DeleteOccurrence )
                </Button>
            </Div>
            <Div>
                <Button Color="Color.Secondary" Clicked="@Cancel">
                    @Localizer.Localize( Scheduler.Localizers?.CancelLocalizer, LocalizationConstants.Cancel )
                </Button>
                <Button Color="Color.Primary" Clicked="@Submit">
                    @Localizer.Localize( Scheduler.Localizers?.SaveLocalizer, LocalizationConstants.Save )
                </Button>
            </Div>
        </ModalFooter>
    </ModalContent>
</Modal>